<?php
    require "sql.php";
    $filename = $_POST['filename'];
    $isPublic = $_POST['isPublic'];
    $username = $_COOKIE['username'];
    $time = date('Y-m-d G:i:s');
    $data = array(
        array(
            'code'=>0
        ),
        array(
            'code'=>1
        ),
        array(
            'code'=>2
        )
    );
    $str1="select * from file where file_name = '".$filename."' and author = '".$username."'";
    $str2 = "insert into file(file_name,author,isPublic,create_time,update_time) values('".$filename."','".$_COOKIE['username']."','".$isPublic."','".$time."','".$time."')";
    $result=$conn->query($str1);
    if ($result->num_rows > 0) {
        echo json_encode($data[0]);       
    }else if($conn->query($str2)){
        echo json_encode($data[1]);
    }else{
        echo json_encode($data[2]);
    };

    $conn->close();